package com.zsl.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Base64Encoder {
    public static String encode(String msg) {
        byte[] b = null;
        try {
            MessageDigest md = MessageDigest.getInstance("md5");
            b = md.digest(msg.getBytes());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        assert b != null;
        StringBuilder md5Str = new StringBuilder(new BigInteger(1, b).toString(16));
        for (int i = 0; i < 32 - md5Str.length(); i++) {
            md5Str.insert(0, "0");
        }
        return md5Str.toString();
    }
}
